$(document).on('click','#btn_search', function(){
    $.mobile.loading( "show");
    var activePage = $.mobile.activePage[0].id;
    product_name = $("#"+activePage+" .product_name").val();
    //alert(product_name);
    select_cat = $("#"+activePage+" .select_cat").find(":selected").val();
    select_loc = $("#"+activePage+" .select_loc").find(":selected").val();
    select_type = $("#"+activePage+" .select_type").find(":selected").val();
    search_function();
})

$(document).on('change','.search_field',function(){
    product_name= $(this).val();
    search_function();
})

function search_function(){
    $.mobile.loading('show');
    page = 1;
    activePage = $.mobile.activePage[0].id;
    $("#"+activePage+" #mypanel").panel("close");
    $("#"+activePage+" #mypanel_myproduct").panel('open');
    var user = '';
    if(activePage == "myproduct"){
        user = user_id;
    }
    $.ajax({
        url:  _host+'topic',
        type: 'GET',
        data: {title: product_name, cat: select_cat, loc: select_loc, type:select_type, page:page, user: user}

    }).done(function(data){
        var j_topic = $.parseJSON(data);
        console.log(j_topic);
        if(j_topic.length != 0){
            $('.ajax_table').empty();
            if(activePage == 'index'){
                for(var i=0; i< j_topic.length ; i = parseInt(i) + 1){
                    render(j_topic[i],'#index .ajax_table');
                }
            }
            else{
                for(var i=0; i< j_topic.length ; i = parseInt(i) + 1){
                    my_render(j_topic[i],"#"+activePage+ " .ajax_table");
                }
            }
        }
        else{
            $('.ajax_table').empty();
            var div_Noresault = '<h3 style="color: #6B6363">Không Tìm Thấy Kết Quả Nào</h3>';
            $("#"+activePage+ " .ajax_table").append(div_Noresault);
        }
        $.mobile.loading( "hide");



    })
}